package ext.tianma.doc.util;

import java.io.IOException;

import wt.method.RemoteAccess;
import wt.util.WTException;
import wt.util.WTProperties;

import com.infoengine.object.factory.Group;
import com.infoengine.util.IEException;

public class TaskUtil implements RemoteAccess{
	private static WTProperties wtproperties=null;
	protected static boolean VERBOSE=true;
	private static String windchillService=null;
	private static String CLASSNAME = TaskUtil.class.getName();
	private static String tablename1 = "RFQ2PLM";

	static 
	{
		try
		{
			wtproperties = WTProperties.getLocalProperties();
			windchillService=wtproperties.getProperty("wt.federation.ie.VMName", "com.tianma.pdmtest.Windchill");
		}
		catch(Throwable throwable)
		{
			throwable.printStackTrace(System.err);
			throw new ExceptionInInitializerError(throwable);
		}
	}
	
	

	
	/**
	 * 根据编号查询物料信息
	 * @param number 要查询物料的编号
	 * @return 查询到的物料编号
	 * @throws IOException
	 * @throws WTException
	 */
	public static Group queryRFQInfoByWhere(String where)
		throws  WTException
	{
		if(VERBOSE)
			System.out.println("要查询物料的条件："+where);
		
		String strColumnName = "*";
		
		com.infoengine.SAK.Task task = new com.infoengine.SAK.Task("ext/tianma/RFQ/QueryObject.xml",windchillService);
		//task.addParam ("TABLENAME",  tablename1 );
		task.addParam ("COLUMNNAME",  strColumnName );
		task.addParam ("WHERE",  where );
		if(VERBOSE)
			System.out.println("where is :"+where);
		try
		{
		    task.invoke();
		}
		catch (IEException iee)
		{
			throw new WTException(iee.getMessage());
		}
		catch (java.io.IOException ioe)
		{
			throw new WTException(ioe.getMessage());
		}
		catch (Exception e)
		{
			throw new WTException(e.getMessage());
		}
		Group g = task.getGroup("QueryObjects");
		//System.out.println("g:"+g.toString());
		if (g != null&&g.getGroup().getChildren().hasMoreElements())
		{
			System.out.println("查到的数据数来那个为："+g.getGroup().getChildCount());
		 /* IeObject ieoRecord = null;
		  for(Enumeration enum1 = g.getGroup().getChildren(); enum1.hasMoreElements();)
		  {
			    //classes each = new classes();
			  	ieoRecord = (IeObject)enum1.nextElement();	
			    String numberSrt=ieoRecord.getAtt("MATNR").getDatum().toString();
			    return numberSrt;
		  }*/
			return g;
		}
		else
		{
			System.out.println("没查询到数据："+where);
		}
		return  null;		
	}	
}
